@extends('admin.layout')
@section('title','修改')
@section('css')
    <style>
        #container{width: 1000px;height: 300px;margin-top: 50px}
        .text-info{margin-left: 30px}
    </style>

@endsection
@section('body')
    @include('vendor.ueditor.assets')
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>修改商品</legend>
    </fieldset>
    <form class="layui-form" action="{{url('goods/update')}}" method="post" enctype="multipart/form-data">
        <div class="layui-form-item">
            <label class="layui-form-label">品名</label>
            <div class="layui-input-inline">
                <input type="text" name="name" value="{{$goods->name}}"  autocomplete="off" placeholder="商品名" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">库存</label>
            <div class="layui-input-inline">
                <input type="number" name="stock" value="{{$goods->stock}}"  autocomplete="off" placeholder="库存" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">价格</label>
            <div class="layui-input-inline">
                <input type="number" name="price" value="{{$goods->price}}"  autocomplete="off" placeholder="价格" class="layui-input">
            </div>

        <div class="layui-form-item">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-inline">
                <select  lay-filter="classify" lay-verify="" lay-search>
                    <option >请选择分类</option>
                    @foreach($all_classify as $value)
                        <option value="{{$value->classify_id}}" @if($value->classify_id==$pa_classify->classify_id) selected @endif>{{$value->name}}</option>
                    @endforeach
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="classify"  id="classify1" lay-filter="classify1" lay-verify="" lay-search>
                    @foreach($son_classify as $value)
                        <option value="{{$value->classify_id}}" @if($value->classify_id==$classify->classify_id) selected @endif>{{$value->name}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <p class="text-info" >上传图片会覆盖以前的，不上传将保持原有</p>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">数量</label>
            <div class="layui-input-inline">
                <select   lay-filter="class_num">
                    <option value="">请选择Banner图数量</option>
                    <option value="1">1张</option>
                    <option value="2">2张</option>
                    <option value="3">3张</option>
                    <option value="4">4张</option>
                    <option value="5">5张</option>
                </select>
            </div>

        </div>
        <div class="layui-form-item" id="banner">
            <label class="layui-form-label">轮播</label>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">封面</label>
            <div class="layui-input-block">
                <input type="file" name="cover" class="" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="上架" checked>
                <input type="radio" name="status" value="2" title="下架" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">详情</label>
            <div class="layui-input-block">
                <script id="container"  name="detail" type="text/plain">{!! $goods->detail !!}</script>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="goods_id" value="{{$goods_id}}">
                <input type="submit" style="margin-top: 100px;width: 300px;" class="btn btn-success" value="修改">
            </div>
        </div>
        {{csrf_field()}}
    </form>

@endsection
@section('js')
    <script>
        @if(Session::has('message'))
            layer.msg("{{Session::get("message")}}");
        {{Session::forget('message')}}
        @endif
        <!-- 实例化编辑器 -->
        var ue = UE.getEditor('container');
        ue.ready(function() {

            ue.execCommand('serverparam', '_token', '{{ csrf_token() }}'); // 设置 CSRF token.
        });

        layui.use(["form",'layer'],function () {
            var form = layui.form();
            form.on('select(classify)', function(data){
                $.post({
                    url:'{{url('classify/lists')}}',
                    data:{'classify_id':data.value,'_token':'{{csrf_token()}}'},
                    success:function (res) {
                        var select;
                        if(res.data==null){
                            select='<option value="">无</option>';
                        }else{
                            for(var i=0;i<res.data.length;i++){
                                select+="<option value='"+res.data[i].classify_id+"'>"+res.data[i].name+"</option>";
                            }
                        }
                        $("#classify1").html(select);
                        form.render('select');
                    }
                })
            });
            form.on('select(class_num)', function(data){
                var banner='<label class="layui-form-label">轮播</label>';
                for(i=0;i<data.value;i++){
                    banner+='<div class="layui-input-block"><input type="file" name="banner[]" class="" ></div>';
                }
                $("#banner").html(banner);
            });
        });
    </script>

@endsection